package test;

import redis.clients.jedis.*;

import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.util.List;

public class PipelineTest {
    private static Jedis createJedit(String host, int port, String passwd) {
        DefaultJedisClientConfig.Builder builder = DefaultJedisClientConfig.builder();
        builder.socketTimeoutMillis(10_000);
        builder.blockingSocketTimeoutMillis(60_000);
        if (passwd != null) {
            builder.password(passwd);
        }
        Jedis jedis = new Jedis(new HostAndPort(host, port), builder.build());
        return jedis;
    }

    public static void main(String args[]) throws InterruptedException, IOException {
        Jedis jedis = createJedit("192.168.0.60", 6379, null);

        System.out.println(jedis.get("aaa"));
        Pipeline pipeline = jedis.pipelined();
        for (int i = 0; i < 100; ++i) {
            Response<String> set1 = pipeline.set("aaa", "bbb");
//            Response<List<String>> list1=  pipeline.blpop(5, "list2");
            pipeline.set("bbb", "ccc");
            Response<Long> long1 = pipeline.strlen("aaa");
            pipeline.hset("h1", "member1", "value1");
            pipeline.hset("h1", "member2", "value2");
            pipeline.hset("h1", "member3", "value3");
            pipeline.hgetAll("h1");
            pipeline.strlen("bbb");
            pipeline.sync();
            System.out.println(set1.get() + "  " + long1.get());
        }
    }
}
